package com.handinfo.uimenu.window;

import java.io.DataInputStream;
import java.util.Vector;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.GameManager;
import com.handinfo.game.AbstractGameActor;
import com.handinfo.game.ActorRole;
import com.handinfo.game.GameScene;
import com.handinfo.uimenu.UIAbstractWindow;
import com.handinfo.uimenu.UIListener;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIPopmenu;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.util.Tools;
import com.test.touch.GameTouchManager;

public class UIRankingLists extends UIAbstractWindow
{

	private static final int WORD_W = UITools.IW_RECTS;//单元列间距
	private static final int WORD_H = UITools.IH_RECTS;//单元行间距
	private static final int LIST_RECT_H = AbstractGameScreen.FONT_H + 2*WORD_H; //单元人员列表的高
	private static final int LIST_H = (UITools.H_RECT - 4*WORD_H - LIST_RECT_H);//列表实际高
	protected static final int LIST_NUMBER = LIST_H/LIST_RECT_H;//一页最大单元列表的行数
	private static final int ROLL_STARTTIME = 20;//单元开始滚动的固定时间
	private static final int ROLL_OVERTIME = 10;//单元滚动结束等待还原的固定时间
	
	private byte m_type;//排行类型  1.家族 2.等级 3.财富 4.击杀 5.贡献 6.战功 7.采集 8.攻伐9.社交
	private String m_titleString;//界面的标题
	private String[] m_labelStrings;//标签的标题
	private int m_label_size;//标签的个数
	private int[] m_label_x;//标签的X
	private int[] m_label_w;//标签的宽
	
	private short m_page_total;//总页数
	private short m_page_index;//当前页数
	private short m_catchPage;//缓存翻页前页数
	private short m_currIndex;//当前选择项
	private short m_infos_size;//内容数量
	private final int WordColour = 0xFFFFFF;//字体颜色
	private boolean[][] m_unitIsRoll;//单元区域是否需要滚动
	private int[][] m_unitRollx;//单元区域的滚动
	private int[][] m_infos_x;//内容的X
	private Vector roleList = new Vector();//成员列表
		
	protected void registerTouch() {
		super.registerTouch();
		clearAllRects();
		registerNormalSoft();
		
		initTouchRect(page);
		
		int size = roleList.size();
		if (size == 0) {
			return;
		}
		int[][] rect = new int[size][];
		for (int i=0;i<LIST_NUMBER;i++) {
			int tempX = m_x + m_label_x[0];
			int tempY = m_y + UITools.INITY_CONTENT + LIST_RECT_H + WORD_H *4 + i*LIST_RECT_H;
//			if( i == m_currIndex ){
//				UITools.drawSelectBox(g, tempX, tempY - WORD_H,UITools.W_RECT, LIST_RECT_H);
//			}
			rect[i] = new int[]{tempX, tempY - WORD_H,UITools.W_RECT, LIST_RECT_H};
		}
		initTouchRect(rect);
	}

	protected void onTouchRect(int[][] rect, int touchid) {
		super.onTouchRect(rect, touchid);
		if (rect == page) {
			switch(touchid) {
			case 0:
				GameTouchManager.keyPressedDir(0);
				break;
			case 1:
				GameTouchManager.keyPressedDir(2);
				break;
			}
		} else {
			if (touchid<roleList.size()) {
				if (m_currIndex == touchid) {
					GameTouchManager.keyPressedFire();
				} else {
					m_currIndex = (short) touchid;
				}
			}
		}
		
	}
	
	int[][] page = new int[][]{
			{182,127,45,22},
			{245,127,45,22},
	};

	public UIRankingLists(int id)
	{
		super(id);
		setBounds(UITools.X_BG, UITools.Y_BG, UITools.W_BG, UITools.H_BG);
	}
    
	/** 根据不通类型初始化不同排行界面数据  */
	protected void initRankingLists(){
	 	switch (m_type) {
			case 1://1.家族
				initJiaZu();
				break;
			case 2://2.等级
				initLevel();
				break;
			case 3://3.财富
				initWealth();
				break;
			case 4://4.击杀
				initKill();
				break;
			case 5://5.贡献
				initContrbution();
				break;
			case 6://6.战功
				initMilitaryExploits();
				break;
			case 7://7.采集
				initCollection();
				break;
			case 8://8.攻伐
				initAttack();
				break;
			case 9://9.社交
				initSocialContact();
				break;
		}	 	
	 	if( m_catchPage != m_page_index ){//不同页改变当前选择位置
			if( m_page_index == 0 && m_catchPage == m_page_total - 1){//如果操作时从最后一页下翻到开始
				m_currIndex = 0;	
			}else if( m_catchPage > m_page_index ){//上翻
				m_currIndex = (short)(m_infos_size - 1);
			}else{//下翻
				m_currIndex = 0;				
			}
		}
	}
	
	/** 初始化标签 
	 * @param int 标签数量
	 * @param String[] 标签名字
	 * @param int[] 标签比例
	 * */
	protected void initGeneralLabel(int NUM,String[] STR, int[] PRO){
		m_label_size = NUM;
		m_labelStrings = null;
		m_labelStrings = STR;
		m_label_x = new int[m_label_size];
		m_label_w = new int[m_label_size];
		int UnitW = (UITools.W_RECT - m_label_size*WORD_W)/10;//内容框的单元宽度
		int[] Proportion  = PRO;//对应的比例份额
		int step = UITools.INITX_CONTENT;
		int width = 0;
		for(int i=0;i<m_label_size;i++){
			m_label_w[i] = Proportion[i]*UnitW;
			m_label_x[i] = step;
			step += (m_label_w[i]+WORD_W);
			width += m_label_w[i]; 
		}
		width += ((m_label_size-1)*WORD_W);
		if( width < UITools.W_RECT ){
			m_label_w[m_label_size-1] += (UITools.W_RECT - width);
		}
		
	}
	
	protected void initJiaZu()
	{
		//标题
		m_titleString = "家族排行";
		//初始化通用标签
		//#if screen == "320240"
		//# String[] temp = {"家族","等级","人数"};
		//#else
		String[] temp = {"家族","等级","人数/上限"};
		//#endif
		int[] pro = {5,2,3};
		initGeneralLabel(temp.length,temp,pro);
		//初始化
        m_unitIsRoll = new boolean[m_infos_size][m_label_size];
        m_unitRollx = new int[m_infos_size][m_label_size];
        m_infos_x = new int[m_infos_size][m_label_size];
        m_rollState = new int[m_label_size];
        m_frameCount = new int[m_label_size];
        m_currframeCount = new int[m_label_size];
        
        int size = roleList.size();
        int tempX = 0;
        int width = 0;
        int ImageW = 0;
        String str1 = "";
        for(int i=0;i<size;i++){
        	SimpleRole role = (SimpleRole) roleList.elementAt(i);
            //单元姓名位置的X
        	tempX =  m_x + m_label_x[0];
        	str1 = "" + role.m_name;
        	switch (role.m_camp) {
				case AbstractGameActor.FACTION_1:
					ImageW = GameScene.s_img_z_icon[0].getWidth();
					break;
				case AbstractGameActor.FACTION_2:
					ImageW = GameScene.s_img_z_icon[1].getWidth();
					break;
				case AbstractGameActor.FACTION_3:
					ImageW = GameScene.s_img_z_icon[2].getWidth();
					break;
				default:
					ImageW = 0;
					break;
			}
        	width = AbstractGameScreen.s_font.stringWidth(str1) + ImageW;
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		//m_infos_x[i][0] = (tempX + ((m_label_w[0] - width) >>1 ));
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}else{
        		m_unitIsRoll[i][0] = true;
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}
        	
        	//单元等级位置X
        	tempX = m_x + m_label_x[1];
        	str1 = ""+role.m_grade;
        	width = AbstractGameScreen.s_font.stringWidth(str1);
        	if( width <= ( m_label_w[1] - 2*WORD_W )){
        		m_infos_x[i][1] = (tempX + ((m_label_w[1] - width) >>1 ));
        	}else{
        		m_unitIsRoll[i][1] = true;
        		m_infos_x[i][1] = (tempX + WORD_W);
        	}
        	
            //单元人数/上限位置X
            tempX = m_x + m_label_x[2];
            str1 = role.m_person + "/" + role.m_maxperson;
        	width = AbstractGameScreen.s_font.stringWidth(str1);
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		m_infos_x[i][2] = (tempX + ((m_label_w[2] - width) >>1 ));
        	}else{
        		m_unitIsRoll[i][2] = true;
        		m_infos_x[i][2] = (tempX + WORD_W);
        	}
        }
	}
	
	protected void initLevel()
	{
		//标题
		m_titleString = "等级排行";
		//初始化通用标签
		String[] temp = {"玩家姓名","等级","职业"};
		int[] pro = {5,2,3};
		initGeneralLabel(temp.length,temp,pro);
		//初始化
        m_unitIsRoll = new boolean[m_infos_size][m_label_size];
        m_unitRollx = new int[m_infos_size][m_label_size];
        m_infos_x = new int[m_infos_size][m_label_size];
        m_rollState = new int[m_label_size];
        m_frameCount = new int[m_label_size];
        m_currframeCount = new int[m_label_size];
        
        int size = roleList.size();
        int tempX = 0;
        int width = 0;
        int ImageW = 0;
        String str1 = "";
        for(int i=0;i<size;i++){
        	SimpleRole role = (SimpleRole) roleList.elementAt(i);
            //单元姓名位置的X
        	tempX =  m_x + m_label_x[0];
        	str1 = "" + role.m_name;
        	switch (role.m_camp) {
				case AbstractGameActor.FACTION_1:
					ImageW = GameScene.s_img_z_icon[0].getWidth();
					break;
				case AbstractGameActor.FACTION_2:
					ImageW = GameScene.s_img_z_icon[1].getWidth();
					break;
				case AbstractGameActor.FACTION_3:
					ImageW = GameScene.s_img_z_icon[2].getWidth();
					break;
				default:
					ImageW = 0;
					break;
			}
        	width = AbstractGameScreen.s_font.stringWidth(str1) + ImageW;
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		//m_infos_x[i][0] = (tempX + ((m_label_w[0] - width) >>1 ));
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}else{
        		m_unitIsRoll[i][0] = true;
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}
        	
        	//单元等级位置X
        	tempX = m_x + m_label_x[1];
        	str1 = ""+role.m_grade;
        	width = AbstractGameScreen.s_font.stringWidth(str1);
        	if( width <= ( m_label_w[1] - 2*WORD_W )){
        		m_infos_x[i][1] = (tempX + ((m_label_w[1] - width) >>1 ));
        	}else{
        		m_unitIsRoll[i][1] = true;
        		m_infos_x[i][1] = (tempX + WORD_W);
        	}
        	
            //单元职业位置X
            tempX = m_x + m_label_x[2];
            str1 =ActorRole.ROLE_VOCATION_LIST[role.m_vocations];
        	width = AbstractGameScreen.s_font.stringWidth(str1);
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		m_infos_x[i][2] = (tempX + ((m_label_w[2] - width) >>1 ));
        	}else{
        		m_unitIsRoll[i][2] = true;
        		m_infos_x[i][2] = (tempX + WORD_W);
        	}
        }

	}
	
	
	protected void initWealth()
	{
		//标题
		m_titleString = "财富排行";
		//初始化通用标签
		String[] temp = {"玩家姓名","金钱"};
		int[] pro = {5,5};
		initGeneralLabel(temp.length,temp,pro);
		//初始化
        m_unitIsRoll = new boolean[m_infos_size][m_label_size];
        m_unitRollx = new int[m_infos_size][m_label_size];
        m_infos_x = new int[m_infos_size][m_label_size];
        m_rollState = new int[m_label_size];
        m_frameCount = new int[m_label_size];
        m_currframeCount = new int[m_label_size];
        
        int size = roleList.size();
        int tempX = 0;
        int width = 0;
        int ImageW = 0;
        String str1 = "";
        for(int i=0;i<size;i++){
        	SimpleRole role = (SimpleRole) roleList.elementAt(i);
            //单元姓名位置的X
        	tempX =  m_x + m_label_x[0];
        	str1 = "" + role.m_name;
			switch (role.m_camp) {
				case AbstractGameActor.FACTION_1:
					ImageW = GameScene.s_img_z_icon[0].getWidth();
					break;
				case AbstractGameActor.FACTION_2:
					ImageW = GameScene.s_img_z_icon[1].getWidth();
					break;
				case AbstractGameActor.FACTION_3:
					ImageW = GameScene.s_img_z_icon[2].getWidth();
					break;
				default:
					ImageW = 0;
					break;
			}
        	width = AbstractGameScreen.s_font.stringWidth(str1) + ImageW;
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		//m_infos_x[i][0] = (tempX + ((m_label_w[0] - width) >>1 ));
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}else{
        		m_unitIsRoll[i][0] = true;
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}
        	
        	//单元金钱位置X
        	tempX = m_x + m_label_x[1];
            m_infos_x[i][1] = (tempX + WORD_W);  
        }
	}
	
	protected void initKill()
	{
		//标题
		m_titleString = "击杀排行";
		//初始化通用标签
		String[] temp = {"玩家姓名","击杀"};
		int[] pro = {5,5};
		initGeneralLabel(temp.length,temp,pro);
		//初始化
        m_unitIsRoll = new boolean[m_infos_size][m_label_size];
        m_unitRollx = new int[m_infos_size][m_label_size];
        m_infos_x = new int[m_infos_size][m_label_size];
        m_rollState = new int[m_label_size];
        m_frameCount = new int[m_label_size];
        m_currframeCount = new int[m_label_size];
        
        int size = roleList.size();
        int tempX = 0;
        int width = 0;
    	int ImageW = 0;
        String str1 = "";
        for(int i=0;i<size;i++){
        	SimpleRole role = (SimpleRole) roleList.elementAt(i);
            //单元姓名位置的X
        	tempX =  m_x + m_label_x[0];
        	str1 = "" + role.m_name;
        	switch (role.m_camp) {
				case AbstractGameActor.FACTION_1:
					ImageW = GameScene.s_img_z_icon[0].getWidth();
					break;
				case AbstractGameActor.FACTION_2:
					ImageW = GameScene.s_img_z_icon[1].getWidth();
					break;
				case AbstractGameActor.FACTION_3:
					ImageW = GameScene.s_img_z_icon[2].getWidth();
					break;
				default:
					ImageW = 0;
					break;
			}
        	width = AbstractGameScreen.s_font.stringWidth(str1)+ImageW;
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		//m_infos_x[i][0] = (tempX + ((m_label_w[0] - width) >>1 ));
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}else{
        		m_unitIsRoll[i][0] = true;
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}
        	
        	//单元击杀位置X
        	tempX = m_x + m_label_x[1];
        	str1 = ""+role.m_kill;
        	width = AbstractGameScreen.s_font.stringWidth(str1);
        	if( width <= ( m_label_w[1] - 2*WORD_W )){
        		m_infos_x[i][1] = (tempX + ((m_label_w[1] - width) >>1 ));
        	}else{
        		m_unitIsRoll[i][1] = true;
        		m_infos_x[i][1] = (tempX + WORD_W);
        	}
        	
        }
	}
	
	protected void initContrbution()
	{
		//标题
		m_titleString = "贡献排行";
		//初始化通用标签
		String[] temp = {"玩家姓名","家族名","贡献值"};
		int[] pro = {4,3,3};
		initGeneralLabel(temp.length,temp,pro);
		//初始化
        m_unitIsRoll = new boolean[m_infos_size][m_label_size];
        m_unitRollx = new int[m_infos_size][m_label_size];
        m_infos_x = new int[m_infos_size][m_label_size];
        m_rollState = new int[m_label_size];
        m_frameCount = new int[m_label_size];
        m_currframeCount = new int[m_label_size];
        
        int size = roleList.size();
        int tempX = 0;
        int width = 0;
    	int ImageW = 0;
        String str1 = "";
        for(int i=0;i<size;i++){
        	SimpleRole role = (SimpleRole) roleList.elementAt(i);
            //单元姓名位置的X
        	tempX =  m_x + m_label_x[0];
        	str1 = "" + role.m_name;
        	switch (role.m_camp) {
				case AbstractGameActor.FACTION_1:
					ImageW = GameScene.s_img_z_icon[0].getWidth();
					break;
				case AbstractGameActor.FACTION_2:
					ImageW = GameScene.s_img_z_icon[1].getWidth();
					break;
				case AbstractGameActor.FACTION_3:
					ImageW = GameScene.s_img_z_icon[2].getWidth();
					break;
				default:
					ImageW = 0;
					break;
			}
        	width = AbstractGameScreen.s_font.stringWidth(str1)+ImageW;
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		//m_infos_x[i][0] = (tempX + ((m_label_w[0] - width) >>1 ));
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}else{
        		m_unitIsRoll[i][0] = true;
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}
        	
        	//单元家族位置X
        	tempX = m_x + m_label_x[1];
        	str1 = ""+role.m_family;
        	width = AbstractGameScreen.s_font.stringWidth(str1);
        	if( width <= ( m_label_w[1] - 2*WORD_W )){
        		m_infos_x[i][1] = (tempX + ((m_label_w[1] - width) >>1 ));
        	}else{
        		m_unitIsRoll[i][1] = true;
        		m_infos_x[i][1] = (tempX + WORD_W);
        	}
        	
            //单元贡献值位置X
            tempX = m_x + m_label_x[2];
            str1 = ""+role.m_contrbution;
        	width = AbstractGameScreen.s_font.stringWidth(str1);
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		m_infos_x[i][2] = (tempX + ((m_label_w[2] - width) >>1 ));
        	}else{
        		m_unitIsRoll[i][2] = true;
        		m_infos_x[i][2] = (tempX + WORD_W);
        	}
        }

	}
	
	protected void initMilitaryExploits()
	{
		//标题
		m_titleString = "战功排行";
		//初始化通用标签
		String[] temp = {"玩家姓名","战功"};
		int[] pro = {5,5};
		initGeneralLabel(temp.length,temp,pro);
		//初始化
        m_unitIsRoll = new boolean[m_infos_size][m_label_size];
        m_unitRollx = new int[m_infos_size][m_label_size];
        m_infos_x = new int[m_infos_size][m_label_size];
        m_rollState = new int[m_label_size];
        m_frameCount = new int[m_label_size];
        m_currframeCount = new int[m_label_size];
        
        int size = roleList.size();
        int tempX = 0;
        int width = 0;
    	int ImageW = 0;
        String str1 = "";
        for(int i=0;i<size;i++){
        	SimpleRole role = (SimpleRole) roleList.elementAt(i);
            //单元姓名位置的X
        	tempX =  m_x + m_label_x[0];
        	str1 = "" + role.m_name;
        	switch (role.m_camp) {
				case AbstractGameActor.FACTION_1:
					ImageW = GameScene.s_img_z_icon[0].getWidth();
					break;
				case AbstractGameActor.FACTION_2:
					ImageW = GameScene.s_img_z_icon[1].getWidth();
					break;
				case AbstractGameActor.FACTION_3:
					ImageW = GameScene.s_img_z_icon[2].getWidth();
					break;
				default:
					ImageW = 0;
					break;
			}
        	width = AbstractGameScreen.s_font.stringWidth(str1)+ImageW;
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		//m_infos_x[i][0] = (tempX + ((m_label_w[0] - width) >>1 ));
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}else{
        		m_unitIsRoll[i][0] = true;
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}
        	
        	//单元战功位置X
        	tempX = m_x + m_label_x[1];
        	str1 = ""+role.m_militaryexploits;
        	width = AbstractGameScreen.s_font.stringWidth(str1);
        	if( width <= ( m_label_w[1] - 2*WORD_W )){
        		m_infos_x[i][1] = (tempX + ((m_label_w[1] - width) >>1 ));
        	}else{
        		m_unitIsRoll[i][1] = true;
        		m_infos_x[i][1] = (tempX + WORD_W);
        	}
        	
        }
	}
	
	protected void initCollection()
	{
		//标题
		m_titleString = "采集排行";
		//初始化通用标签
		String[] temp = {"玩家姓名","采集量"};
		int[] pro = {5,5};
		initGeneralLabel(temp.length,temp,pro);
		//初始化
        m_unitIsRoll = new boolean[m_infos_size][m_label_size];
        m_unitRollx = new int[m_infos_size][m_label_size];
        m_infos_x = new int[m_infos_size][m_label_size];
        m_rollState = new int[m_label_size];
        m_frameCount = new int[m_label_size];
        m_currframeCount = new int[m_label_size];
        
        int size = roleList.size();
        int tempX = 0;
        int width = 0;
    	int ImageW = 0;
        String str1 = "";
        for(int i=0;i<size;i++){
        	SimpleRole role = (SimpleRole) roleList.elementAt(i);
            //单元姓名位置的X
        	tempX =  m_x + m_label_x[0];
        	str1 = "" + role.m_name;
        	switch (role.m_camp) {
				case AbstractGameActor.FACTION_1:
					ImageW = GameScene.s_img_z_icon[0].getWidth();
					break;
				case AbstractGameActor.FACTION_2:
					ImageW = GameScene.s_img_z_icon[1].getWidth();
					break;
				case AbstractGameActor.FACTION_3:
					ImageW = GameScene.s_img_z_icon[2].getWidth();
					break;
				default:
					ImageW = 0;
					break;
			}
        	width = AbstractGameScreen.s_font.stringWidth(str1)+ImageW;
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		//m_infos_x[i][0] = (tempX + ((m_label_w[0] - width) >>1 ));
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}else{
        		m_unitIsRoll[i][0] = true;
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}
        	
        	//单元采集位置X
        	tempX = m_x + m_label_x[1];
        	str1 = ""+role.m_collection;
        	width = AbstractGameScreen.s_font.stringWidth(str1);
        	if( width <= ( m_label_w[1] - 2*WORD_W )){
        		m_infos_x[i][1] = (tempX + ((m_label_w[1] - width) >>1 ));
        	}else{
        		m_unitIsRoll[i][1] = true;
        		m_infos_x[i][1] = (tempX + WORD_W);
        	}
        	
        }
	}
	
	protected void initAttack()
	{
		//标题
		m_titleString = "攻伐排行";
		//初始化通用标签
		String[] temp = {"玩家姓名","成功次数"};
		int[] pro = {5,5};
		initGeneralLabel(temp.length,temp,pro);
		//初始化
        m_unitIsRoll = new boolean[m_infos_size][m_label_size];
        m_unitRollx = new int[m_infos_size][m_label_size];
        m_infos_x = new int[m_infos_size][m_label_size];
        m_rollState = new int[m_label_size];
        m_frameCount = new int[m_label_size];
        m_currframeCount = new int[m_label_size];
        
        int size = roleList.size();
        int tempX = 0;
        int width = 0;
    	int ImageW = 0;
        String str1 = "";
        for(int i=0;i<size;i++){
        	SimpleRole role = (SimpleRole) roleList.elementAt(i);
            //单元姓名位置的X
        	tempX =  m_x + m_label_x[0];
        	str1 = "" + role.m_name;
        	switch (role.m_camp) {
				case AbstractGameActor.FACTION_1:
					ImageW = GameScene.s_img_z_icon[0].getWidth();
					break;
				case AbstractGameActor.FACTION_2:
					ImageW = GameScene.s_img_z_icon[1].getWidth();
					break;
				case AbstractGameActor.FACTION_3:
					ImageW = GameScene.s_img_z_icon[2].getWidth();
					break;
				default:
					ImageW = 0;
					break;
			}
        	width = AbstractGameScreen.s_font.stringWidth(str1)+ImageW;
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		//m_infos_x[i][0] = (tempX + ((m_label_w[0] - width) >>1 ));
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}else{
        		m_unitIsRoll[i][0] = true;
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}
        	
        	//单元成功次数位置X
        	tempX = m_x + m_label_x[1];
        	str1 = ""+role.m_attack;
        	width = AbstractGameScreen.s_font.stringWidth(str1);
        	if( width <= ( m_label_w[1] - 2*WORD_W )){
        		m_infos_x[i][1] = (tempX + ((m_label_w[1] - width) >>1 ));
        	}else{
        		m_unitIsRoll[i][1] = true;
        		m_infos_x[i][1] = (tempX + WORD_W);
        	}
        	
        }
	}
	
	protected void initSocialContact()
	{
		//标题
		m_titleString = "社交排行";
		//初始化通用标签
		String[] temp = {"玩家姓名","知名度"};
		int[] pro = {5,5};
		initGeneralLabel(temp.length,temp,pro);
		//初始化
        m_unitIsRoll = new boolean[m_infos_size][m_label_size];
        m_unitRollx = new int[m_infos_size][m_label_size];
        m_infos_x = new int[m_infos_size][m_label_size];
        m_rollState = new int[m_label_size];
        m_frameCount = new int[m_label_size];
        m_currframeCount = new int[m_label_size];
        
        int size = roleList.size();
        int tempX = 0;
        int width = 0;
    	int ImageW = 0;
        String str1 = "";
        for(int i=0;i<size;i++){
        	SimpleRole role = (SimpleRole) roleList.elementAt(i);
            //单元姓名位置的X
        	tempX =  m_x + m_label_x[0];
        	str1 = "" + role.m_name;
        	switch (role.m_camp) {
				case AbstractGameActor.FACTION_1:
					ImageW = GameScene.s_img_z_icon[0].getWidth();
					break;
				case AbstractGameActor.FACTION_2:
					ImageW = GameScene.s_img_z_icon[1].getWidth();
					break;
				case AbstractGameActor.FACTION_3:
					ImageW = GameScene.s_img_z_icon[2].getWidth();
					break;
				default:
					ImageW = 0;
					break;
			}
        	width = AbstractGameScreen.s_font.stringWidth(str1)+ImageW;
        	if( width <= ( m_label_w[0] - 2*WORD_W )){
        		//m_infos_x[i][0] = (tempX + ((m_label_w[0] - width) >>1 ));
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}else{
        		m_unitIsRoll[i][0] = true;
        		m_infos_x[i][0] = (tempX + WORD_W);
        	}
        	
        	//单元知名度数位置X
        	tempX = m_x + m_label_x[1];
        	str1 = ""+role.m_popularity;
        	width = AbstractGameScreen.s_font.stringWidth(str1);
        	if( width <= ( m_label_w[1] - 2*WORD_W )){
        		m_infos_x[i][1] = (tempX + ((m_label_w[1] - width) >>1 ));
        	}else{
        		m_unitIsRoll[i][1] = true;
        		m_infos_x[i][1] = (tempX + WORD_W);
        	}
        	
        }
	}
	
	protected void paintContent(Graphics g)
	{
		// 绘制背景
		UITools.paintBackGround(g, UITools.X_BG, UITools.Y_BG, UITools.W_BG,
						UITools.H_BG, m_titleString, true, true);
		int tempX = 0;
		int tempY = 0;
		// 绘制标签和内容框
		for( int i=0;i<m_label_size;i++){
			tempX = m_x + m_label_x[i];
			tempY = m_y + UITools.INITY_CONTENT + WORD_H;
			UITools.drawListTitleItem(g, tempX, tempY,
					m_label_w[i], LIST_RECT_H, m_labelStrings[i]);
			UITools.drawListFrame(g, tempX, tempY + LIST_RECT_H + WORD_H, m_label_w[i],LIST_H);
		}
		// 绘制内容
		paintInfos(g);
		// 绘制翻页
		if( m_page_total > 0 ){
			UITools.paintPage(g, m_x + (m_w >> 1), m_y + m_h - UITools.IW_WIN, m_page_index, m_page_total);
		}		
	}
    
	/** 绘制内容 */
	protected void paintInfos(Graphics g)
	{
		switch(m_type){
			case 1://家族排行
				paintFamilyRankingList(g, WordColour);
				break;
			case 2://等级排行
				paintLevelRankingList(g,WordColour);
				break;
			case 3://财富排行
				paintWealthRankingList(g, WordColour);
				break;
			case 4://击杀排行
				paintKillRankingList(g, WordColour);
				break;
			case 5://贡献排行
				paintContrbutionRankingList(g, WordColour);
				break;
			case 6://战功排行
				paintMilitaryExploitsRankingList(g, WordColour);
				break;
			case 7://采集排行
				paintCollectionRankingList(g, WordColour);
				break;
			case 8://攻伐排行
				paintAttackRankingList(g, WordColour);
				break;
			case 9://社交排行
				paintSocialContactRankingList(g, WordColour);
				break;
		}
	}
	
	/** 绘制名字 */
	protected void paintName(Graphics g, SimpleRole ROLE, int TempX, int TempY, int Colour)
	{
		int index = 0;
		if (ROLE != null) {
			switch (ROLE.m_camp) {
				case AbstractGameActor.FACTION_1://昆
					index = GameScene.ZHEN_ICON_KL;
					paintImageAndString(g, GameScene.s_img_z_icon[index], ROLE.m_name, TempX, TempY, Colour);
					break;
				case AbstractGameActor.FACTION_2://泰
					index = GameScene.ZHEN_ICON_TS;
					paintImageAndString(g, GameScene.s_img_z_icon[index], ROLE.m_name, TempX, TempY, Colour);
					break;
				case AbstractGameActor.FACTION_3://洞
					index = GameScene.ZHEN_ICON_DT;
					paintImageAndString(g, GameScene.s_img_z_icon[index], ROLE.m_name, TempX, TempY, Colour);
					break;
				default:
					paintString(g, ROLE.m_name, TempX, TempY, Colour);
					break;
			}
		}
	}
	
	/** 单独绘制 字符串 */
	protected void paintString(Graphics g,String STR,int x,int y,int Colour)
	{
		if(STR != null ){
			g.setColor(Colour);
			g.drawString(STR, x, y, 0);
		}
	}
	
	/** 绘制字符串加图 */
	protected void paintImageAndString(Graphics g, Image IMG, String STR, int x, int y, int Colour)
	{
		int WordW = 1;
		if (IMG != null) {
			g.drawImage(IMG, x, y, 0);
		}
		if (STR != null) {
			g.setColor(Colour);
			g.drawString(STR, x + IMG.getWidth() + WordW, y, 0);
		}
	}
	
	/** 绘制家族排行内容  */
	protected void paintFamilyRankingList(Graphics g,int Colour)
	{
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		if( roleList != null && roleList.size() > 0 ){
			for(int i=0;i<roleList.size();i++){
				SimpleRole role = (SimpleRole)roleList.elementAt(i);
				int tempX = m_x + m_label_x[0];
				int tempY = m_y + UITools.INITY_CONTENT + LIST_RECT_H + WORD_H *4 + i*LIST_RECT_H;
				if( i == m_currIndex ){
					UITools.drawSelectBox(g, tempX, tempY - WORD_H,UITools.W_RECT, LIST_RECT_H);
				}
			    tempX = m_infos_x[i][0] - m_unitRollx[i][0];
				//绘制名字
			    int tempW = (m_label_w[0] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][0], tempY, tempW, LIST_RECT_H);
			    paintName(g, role, tempX, tempY, Colour);
			    //绘制等级
			    tempW = (m_label_w[1] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][1], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][1] - m_unitRollx[i][1];
			    paintString(g, ""+role.m_grade, tempX, tempY, Colour);
			    //绘制人数/上限
			    tempW = (m_label_w[2] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][2], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][2] - m_unitRollx[i][2];
			    String str = role.m_person + "/"+ role.m_maxperson;
			    paintString(g, str, tempX, tempY, Colour);
				
			}
		}
	}
	
	/** 绘制等级排行内容  */
	protected void paintLevelRankingList(Graphics g,int Colour)
	{
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		if( roleList != null && roleList.size() > 0 ){
			for(int i=0;i<roleList.size();i++){
				SimpleRole role = (SimpleRole)roleList.elementAt(i);
				int tempX = m_x + m_label_x[0];
				int tempY = m_y + UITools.INITY_CONTENT + LIST_RECT_H + WORD_H *4 + i*LIST_RECT_H;
				if( i == m_currIndex ){
					UITools.drawSelectBox(g, tempX, tempY - WORD_H,UITools.W_RECT, LIST_RECT_H);
				}
			    tempX = m_infos_x[i][0] - m_unitRollx[i][0];
				//绘制名字
			    int tempW = (m_label_w[0] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][0], tempY, tempW, LIST_RECT_H);
			    paintName(g, role, tempX, tempY, Colour);
			    //绘制等级
			    tempW = (m_label_w[1] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][1], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][1] - m_unitRollx[i][1];
			    paintString(g, ""+role.m_grade, tempX, tempY, Colour);
			    //绘制职业
			    tempW = (m_label_w[2] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][2], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][2] - m_unitRollx[i][2];
			    paintString(g, ActorRole.ROLE_VOCATION_LIST[role.m_vocations], tempX, tempY, Colour);
				
			}
		}
	}
	
	/** 绘制财富排行内容  */
	protected void paintWealthRankingList(Graphics g,int Colour)
	{
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		if( roleList != null && roleList.size() > 0 ){
			for(int i=0;i<roleList.size();i++){
				SimpleRole role = (SimpleRole)roleList.elementAt(i);
				int tempX = m_x + m_label_x[0];
				int tempY = m_y + UITools.INITY_CONTENT + LIST_RECT_H + WORD_H *4 + i*LIST_RECT_H;
				if( i == m_currIndex ){
					UITools.drawSelectBox(g, tempX, tempY - WORD_H,UITools.W_RECT, LIST_RECT_H);
				}
			    tempX = m_infos_x[i][0] - m_unitRollx[i][0];
				//绘制名字
			    int tempW = (m_label_w[0] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][0], tempY, tempW, LIST_RECT_H);
			    paintName(g, role, tempX, tempY, Colour);
			    
			    //绘制金钱
			    tempW = m_label_w[1];
			    g.setClip( m_infos_x[i][1], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][1];
			    UITools.paintMoneyGameLT(g, tempX, tempY, role.m_money, false);
				
			}
		}
	}
	
	/** 绘制击杀排行内容  */
	protected void paintKillRankingList(Graphics g,int Colour)
	{
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		if( roleList != null && roleList.size() > 0 ){
			for(int i=0;i<roleList.size();i++){
				SimpleRole role = (SimpleRole)roleList.elementAt(i);
				int tempX = m_x + m_label_x[0];
				int tempY = m_y + UITools.INITY_CONTENT + LIST_RECT_H + WORD_H *4 + i*LIST_RECT_H;
				if( i == m_currIndex ){
					UITools.drawSelectBox(g, tempX, tempY - WORD_H,UITools.W_RECT, LIST_RECT_H);
				}
			    tempX = m_infos_x[i][0] - m_unitRollx[i][0];
				//绘制名字
			    int tempW = (m_label_w[0] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][0], tempY, tempW, LIST_RECT_H);
			    paintName(g, role, tempX, tempY, Colour);
			    
			    //绘制击杀
			    tempW = (m_label_w[1] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][1], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][1] - m_unitRollx[i][1];
			    paintString(g, ""+role.m_kill, tempX, tempY, Colour);			  			
			}
		}
	}
	
	/** 绘制贡献排行内容  */
	protected void paintContrbutionRankingList(Graphics g,int Colour)
	{
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		if( roleList != null && roleList.size() > 0 ){
			for(int i=0;i<roleList.size();i++){
				SimpleRole role = (SimpleRole)roleList.elementAt(i);
				int tempX = m_x + m_label_x[0];
				int tempY = m_y + UITools.INITY_CONTENT + LIST_RECT_H + WORD_H *4 + i*LIST_RECT_H;
				if( i == m_currIndex ){
					UITools.drawSelectBox(g, tempX, tempY - WORD_H,UITools.W_RECT, LIST_RECT_H);
				}
			    tempX = m_infos_x[i][0] - m_unitRollx[i][0];
				//绘制名字
			    int tempW = (m_label_w[0] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][0], tempY, tempW, LIST_RECT_H);
			    paintName(g, role, tempX, tempY, Colour);
				
			    //绘制家族
			    tempW = (m_label_w[1] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][1], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][1] - m_unitRollx[i][1];
			    paintString(g, ""+role.m_family, tempX, tempY, Colour);
			    //绘制贡献值
			    tempW = (m_label_w[2] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][2], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][2] - m_unitRollx[i][2];
			    paintString(g, ""+role.m_contrbution, tempX, tempY, Colour);
				
			}
		}
	}
	
	/** 绘制战功排行内容  */
	protected void paintMilitaryExploitsRankingList(Graphics g,int Colour)
	{
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		if( roleList != null && roleList.size() > 0 ){
			for(int i=0;i<roleList.size();i++){
				SimpleRole role = (SimpleRole)roleList.elementAt(i);
				int tempX = m_x + m_label_x[0];
				int tempY = m_y + UITools.INITY_CONTENT + LIST_RECT_H + WORD_H *4 + i*LIST_RECT_H;
				if( i == m_currIndex ){
					UITools.drawSelectBox(g, tempX, tempY - WORD_H,UITools.W_RECT, LIST_RECT_H);
				}
			    tempX = m_infos_x[i][0] - m_unitRollx[i][0];
				//绘制名字
			    int tempW = (m_label_w[0] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][0], tempY, tempW, LIST_RECT_H);
			    paintName(g, role, tempX, tempY, Colour);
			    
			    //绘制战功
			    tempW = (m_label_w[1] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][1], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][1] - m_unitRollx[i][1];
			    paintString(g, ""+role.m_militaryexploits, tempX, tempY, Colour);			  			
			}
		}
	}
	
	/** 绘制采集排行内容  */
	protected void paintCollectionRankingList(Graphics g,int Colour)
	{
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		if( roleList != null && roleList.size() > 0 ){
			for(int i=0;i<roleList.size();i++){
				SimpleRole role = (SimpleRole)roleList.elementAt(i);
				int tempX = m_x + m_label_x[0];
				int tempY = m_y + UITools.INITY_CONTENT + LIST_RECT_H + WORD_H *4 + i*LIST_RECT_H;
				if( i == m_currIndex ){
					UITools.drawSelectBox(g, tempX, tempY - WORD_H,UITools.W_RECT, LIST_RECT_H);
				}
			    tempX = m_infos_x[i][0] - m_unitRollx[i][0];
				//绘制名字
			    int tempW = (m_label_w[0] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][0], tempY, tempW, LIST_RECT_H);
			    paintName(g, role, tempX, tempY, Colour);
			    //绘制采集量
			    tempW = (m_label_w[1] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][1], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][1] - m_unitRollx[i][1];
			    paintString(g, ""+role.m_collection, tempX, tempY, Colour);			  			
			}
		}
	}
	
	/** 绘制攻伐排行内容  */
	protected void paintAttackRankingList(Graphics g,int Colour)
	{
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		if( roleList != null && roleList.size() > 0 ){
			for(int i=0;i<roleList.size();i++){
				SimpleRole role = (SimpleRole)roleList.elementAt(i);
				int tempX = m_x + m_label_x[0];
				int tempY = m_y + UITools.INITY_CONTENT + LIST_RECT_H + WORD_H *4 + i*LIST_RECT_H;
				if( i == m_currIndex ){
					UITools.drawSelectBox(g, tempX, tempY - WORD_H,UITools.W_RECT, LIST_RECT_H);
				}
			    tempX = m_infos_x[i][0] - m_unitRollx[i][0];
				//绘制名字
			    int tempW = (m_label_w[0] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][0], tempY, tempW, LIST_RECT_H);
			    paintName(g, role, tempX, tempY, Colour);
			    
			    //绘制成功次数
			    tempW = (m_label_w[1] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][1], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][1] - m_unitRollx[i][1];
			    paintString(g, ""+role.m_attack, tempX, tempY, Colour);			  			
			}
		}
	}
	
	/** 绘制社交排行内容  */
	protected void paintSocialContactRankingList(Graphics g,int Colour)
	{
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		if( roleList != null && roleList.size() > 0 ){
			for(int i=0;i<roleList.size();i++){
				SimpleRole role = (SimpleRole)roleList.elementAt(i);
				int tempX = m_x + m_label_x[0];
				int tempY = m_y + UITools.INITY_CONTENT + LIST_RECT_H + WORD_H *4 + i*LIST_RECT_H;
				if( i == m_currIndex ){
					UITools.drawSelectBox(g, tempX, tempY - WORD_H,UITools.W_RECT, LIST_RECT_H);
				}
			    tempX = m_infos_x[i][0] - m_unitRollx[i][0];
				//绘制名字
			    int tempW = (m_label_w[0] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][0], tempY, tempW, LIST_RECT_H);
			    paintName(g, role, tempX, tempY, Colour);
			    
			    //绘制知名度
			    tempW = (m_label_w[1] - 2 *WORD_W);
			    g.setClip( m_infos_x[i][1], tempY, tempW, LIST_RECT_H);
			    tempX =  m_infos_x[i][1] - m_unitRollx[i][1];
			    paintString(g, ""+role.m_popularity, tempX, tempY, Colour);			  			
			}
		}
	}
	
	protected void keyLogic()
	{
        unitRollx();
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			close();
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
			changUpIndex();
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
			changDownIndex();
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
			changLeftPage();
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
			changRightPage();
		}else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
			if( m_type == 1){
				FamilyOperation();
			}else{
				Operation();	
			}
		}
	}
	
	private int[] m_rollState;//单元当前滚动状态  ：0开始等待 1滚动中 2滚动结束等待中
	private int[] m_frameCount;//计算单元滚动时间 用帧数计算
	public int[]  m_currframeCount;
	
	private void unitRollx()
	{
		if (m_unitIsRoll == null || m_unitRollx == null || m_currIndex >= m_unitIsRoll.length) {
			return;
		}
		for (int i = 0; i < m_label_size; i++) {
			if (m_unitIsRoll[m_currIndex][i]) {//判断滚动处理  条件必须是当前选中的单元需要滚动
				m_currframeCount[i]++;
				if (m_currframeCount[i] < 0) {
					m_currframeCount[i] = 0;
				}
				switch (m_rollState[i]) {//当前需要滚动单元的状态
					case 0://开始等待
						if (m_frameCount[i] == 0) {
							m_frameCount[i] = m_currframeCount[i];
						}
						else if (m_currframeCount[i] - m_frameCount[i] >= ROLL_STARTTIME) {
							m_rollState[i] = 1;
							m_frameCount[i] = 0;
						}
						break;
					case 1://滚动中
						if (m_unitRollx[m_currIndex][i] < m_label_w[i] - (UITools.IW_RECT_CONTENT << 1)) {
							m_unitRollx[m_currIndex][i]++;
						}
						else {
							m_rollState[i] = 2;
						}
						break;
					case 2://结束等待
						if (m_frameCount[i] == 0) {
							//m_frameCount = GameManager.getInstance().m_scene.m_frameCount;
							m_frameCount[i] = m_currframeCount[i];
						}
						else if (m_currframeCount[i] - m_frameCount[i] >= ROLL_OVERTIME) {
							m_rollState[i] = 0;
							m_frameCount[i] = 0;
							m_unitRollx[m_currIndex][i] = 0;
						}
						break;
				}
			}
		}
	}
	
	/** 判断如果当前选项离开重置偏移量 */
    private void returnUnitRollx(){
    	for( int i=0; i < m_unitRollx.length;i++){
    		if( m_currIndex != i ){
    			for(int h=0;h<m_label_size;h++){
            		m_unitRollx[i][h] = 0;
        		}
    		} 		
    	}
    }
    
	private void changUpIndex(){
		if( m_currIndex == 0 && m_page_index == 0){
			return;
		}else{
			if( m_currIndex == 0 ){
				m_catchPage = m_page_index;
				GameManager.getInstance().m_game_message.sendRankingList( m_type,(short)(m_page_index - 1), (short)LIST_NUMBER);
			}else{
				m_currIndex --;
				returnUnitRollx();
			}
		}
	}
	
	private void changDownIndex(){
		if( m_currIndex == m_infos_size -1 && m_page_index == m_page_total -1 ){
			return;
		}else{
			if( m_currIndex == m_infos_size -1 ){
				m_catchPage = m_page_index;
				GameManager.getInstance().m_game_message.sendRankingList( m_type, (short)(m_page_index + 1), (short)LIST_NUMBER);
			}else{
				m_currIndex ++;
				returnUnitRollx();
			}
		}
	}
	
	private void changLeftPage(){
		if( m_page_index == 0 ){
			return;
		}else{
			m_catchPage = m_page_index;
			GameManager.getInstance().m_game_message.sendRankingList( m_type,(short)(m_page_index - 1), (short)LIST_NUMBER);
		}
	}
	
    private void changRightPage(){
		if( m_page_index == m_page_total - 1 ){
			return;
		}else{
			m_catchPage = m_page_index;
			GameManager.getInstance().m_game_message.sendRankingList( m_type,(short)(m_page_index + 1), (short)LIST_NUMBER);
		}
	}
	
  //家族排行操作
  	private void FamilyOperation(){
  		
  		if ( roleList == null || roleList.size() == 0) {
  			return;
  		}
  		String[] nearTeamItems = new String[] { "1.申请加入", "2.查看家族" };
  		final UIPopmenu win = (UIPopmenu) UIManager.getInstance().createWindow(
  				UIWindowFactory.WINDOW_POPMENU);
  		win.setPopmenus(nearTeamItems);
  		win.addListener(new UIListener() {

  			public void actionPerformed()
  								{
  				if (AbstractGameScreen
  						.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {// 申请加入
  					applyJion(roleList);
  					UIManager.getInstance().removeWindow(win);
  				}
  				else if (AbstractGameScreen
  						.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {// 查看家族
  					seeFamily(roleList);
  					UIManager.getInstance().removeWindow(win);
  				}
  				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
  						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
  					switch (win.getCurrentIndex()) {
  						case 0:// 申请加入
  							applyJion(roleList);
  							break;
  						case 1:// 查看家族
  							seeFamily(roleList);
  							break;
  					}
  					UIManager.getInstance().removeWindow(win);
  				}
  				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)
  						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {
  					UIManager.getInstance().removeWindow(win);
  				}
  			}
  		});
  	}
	//排行操作
	private void Operation(){
		
		if ( roleList == null || roleList.size() == 0) {
			return;
		}
		String[] nearTeamItems = new String[] { "1.查看", "2.传音入密" };
		final UIPopmenu win = (UIPopmenu) UIManager.getInstance().createWindow(
				UIWindowFactory.WINDOW_POPMENU);
		win.setPopmenus(nearTeamItems);
		win.addListener(new UIListener() {

			public void actionPerformed()
								{
				if (AbstractGameScreen
						.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {// 查看
					seeRole(roleList);
					UIManager.getInstance().removeWindow(win);
				}
				else if (AbstractGameScreen
						.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {// 密语
					writeMsg(roleList);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					switch (win.getCurrentIndex()) {
						case 0:// 查看
							Tools.debugPrintln("查看");
							seeRole(roleList);
							break;
						case 1:// 密語
							Tools.debugPrintln("密语");
							writeMsg(roleList);
							break;
					}
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {
					UIManager.getInstance().removeWindow(win);
				}
			}
		});
	}
	
	/**
	 * 申请加入
	 */
	private void applyJion(Vector list){
		GameManager.getInstance().m_game_message.sendFamilyApplyAdd(getIndexID(list));
	}
	/**
	 * 查看家族
	 */
	private void seeFamily(Vector list){
		GameManager.getInstance().m_game_message.sendFamilyOtherMessage(getIndexID(list));
	}
	
	/**
	 * 私聊
	 */
	private void writeMsg(Vector list)
	{
		UIChatInsert.gotoSiliao(getIndexID(list), getIndexName(list));
	}

	/**
	 * 查看玩家属性
	 */
	private void seeRole(Vector list)
	{
		GameManager.getInstance().m_game_message.sendAttInfos(getIndexID(list));
	}
	
	/**
	 * 根据列表的数据的下标 找到对应人物的ID
	 * 
	 * @return role.m_gameID
	 */
	private long getIndexID(Vector list)
	{
		if ( m_currIndex < 0) {
			return 0;
		}
		Vector roleList = list;
		SimpleRole role = (SimpleRole) roleList.elementAt(m_currIndex);
		return role.m_gameID;
	}

	/**
	 * 根据列表的数据的下标 找到对应人物的name
	 * 
	 * @return role.m_gameID
	 */
	private String getIndexName(Vector list)
	{
		if (m_currIndex < 0) {
			return "";
		}
		Vector roleList = list;
		SimpleRole role = (SimpleRole) roleList.elementAt(m_currIndex);
		return role.m_name;
	}
	
	/** 创建等级排行界面 */
	public static final void recvFamilyRankingList(DataInputStream dis)
	{
		UIRankingLists win = (UIRankingLists)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_GRADERANK);
		if( win == null ){
			win = (UIRankingLists)UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_GRADERANK);
		}
		try{
			win.m_type = 1;
			synchronized (win) {
				win.roleList.removeAllElements();
				win.m_page_index = dis.readShort();//当前页数
				win.m_page_total = dis.readShort();//总页数
				win.m_infos_size = dis.readShort();//当前页内容数量
//				Tools.debugPrintln("总页数="+win.m_infos_size);
				if( win.m_infos_size > LIST_NUMBER ){
					win.m_infos_size = (short)LIST_NUMBER;
				}
				for (int i = 0; i < win.m_infos_size; i++) {
					SimpleRole role = new SimpleRole();
					role.m_gameID = dis.readLong(); //id 
					role.m_name = dis.readUTF(); //名字
					role.m_grade = dis.readInt(); //等级
					role.m_camp = dis.readByte();//阵营
					role.m_person = dis.readInt();//人数
					role.m_maxperson = dis.readInt();//最大人数
					win.roleList.addElement(role);
				}
				win.initRankingLists();				
			}
			GameManager.getInstance().m_game_message.unlockNetwork();
		}catch (Exception e) {
			GameManager.getInstance().m_game_message.unlockNetwork();
			Tools.debug(e);
		}
		win.registerTouch();
	}
	
	/** 创建等级排行界面 */
	public static final void recvLevelRankingList(DataInputStream dis)
	{
		UIRankingLists win = (UIRankingLists)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_GRADERANK);
		if( win == null ){
			win = (UIRankingLists)UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_GRADERANK);
		}
		try{
			win.m_type = 2;
			synchronized (win) {
				win.roleList.removeAllElements();
				win.m_page_index = dis.readShort();//当前页数
				win.m_page_total = dis.readShort();//总页数
				win.m_infos_size = dis.readShort();//当前页内容数量
				if( win.m_infos_size > LIST_NUMBER ){
					win.m_infos_size = (short)LIST_NUMBER;
				}
				for (int i = 0; i < win.m_infos_size; i++) {
					SimpleRole role = new SimpleRole();
					role.m_gameID = dis.readLong(); //id 
					role.m_name = dis.readUTF(); //名字
					role.m_grade = dis.readInt(); //等级
					short jobsize = dis.readShort(); //转职个数
					role.m_vocation = new byte[jobsize];
					for (int j = 0; j < jobsize; j++) {
						role.m_vocation[j] = dis.readByte();
					}
					role.m_vocations = role.m_vocation[jobsize-1];
					role.m_camp = dis.readByte();//阵营
					//Tools.debugPrintln("name="+role.m_name+";camp="+role.m_camp);
					win.roleList.addElement(role);
				}
				win.initRankingLists();				
			}
			GameManager.getInstance().m_game_message.unlockNetwork();
		}catch (Exception e) {
			GameManager.getInstance().m_game_message.unlockNetwork();
			Tools.debug(e);
		}	
		win.registerTouch();
	}
	
	/** 创建财富排行界面 */
	public static final void recvWealthRankingList(DataInputStream dis)
	{
		UIRankingLists win = (UIRankingLists)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_GRADERANK);
		if( win == null ){
			win = (UIRankingLists)UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_GRADERANK);
		}
		try{
			win.m_type = 3;
			synchronized (win) {
				win.roleList.removeAllElements();
				win.m_page_index = dis.readShort();//当前页数
				win.m_page_total = dis.readShort();//总页数
				win.m_infos_size = dis.readShort();//当前页内容数量
				if( win.m_infos_size > LIST_NUMBER ){
					win.m_infos_size = (short)LIST_NUMBER;
				}
				for (int i = 0; i < win.m_infos_size; i++) {
					SimpleRole role = new SimpleRole();
					role.m_gameID = dis.readLong(); //id 
					role.m_name = dis.readUTF(); //名字
					role.m_money = dis.readLong();//金钱
					role.m_camp = dis.readByte();//阵营
					
					win.roleList.addElement(role);
				}
				win.initRankingLists();				
			}
			GameManager.getInstance().m_game_message.unlockNetwork();
		}catch (Exception e) {
			GameManager.getInstance().m_game_message.unlockNetwork();
			Tools.debug(e);
		}	
		win.registerTouch();
	}
	
	/** 创建击杀排行界面 */
	public static final void recvKillRankingList(DataInputStream dis)
	{
		UIRankingLists win = (UIRankingLists)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_GRADERANK);
		if( win == null ){
			win = (UIRankingLists)UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_GRADERANK);
		}
		try{
			win.m_type = 4;
			synchronized (win) {
				win.roleList.removeAllElements();
				win.m_page_index = dis.readShort();//当前页数
				win.m_page_total = dis.readShort();//总页数
				win.m_infos_size = dis.readShort();//当前页内容数量
				if( win.m_infos_size > LIST_NUMBER ){
					win.m_infos_size = (short)LIST_NUMBER;
				}
				for (int i = 0; i < win.m_infos_size; i++) {
					SimpleRole role = new SimpleRole();
					role.m_gameID = dis.readLong(); //id 
					role.m_name = dis.readUTF(); //名字
					role.m_kill = dis.readInt();//击杀
					role.m_camp = dis.readByte();//阵营
					win.roleList.addElement(role);
				}
				win.initRankingLists();				
			}
			GameManager.getInstance().m_game_message.unlockNetwork();
		}catch (Exception e) {
			GameManager.getInstance().m_game_message.unlockNetwork();
			Tools.debug(e);
		}	
		win.registerTouch();
	}
	
	/** 创建贡献排行界面 */
	public static final void recvContrbutionRankingList(DataInputStream dis)
	{
		UIRankingLists win = (UIRankingLists)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_GRADERANK);
		if( win == null ){
			win = (UIRankingLists)UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_GRADERANK);
		}
		try{
			win.m_type = 5;
			synchronized (win) {
				win.roleList.removeAllElements();
				win.m_page_index = dis.readShort();//当前页数
				win.m_page_total = dis.readShort();//总页数
				win.m_infos_size = dis.readShort();//当前页内容数量
				if( win.m_infos_size > LIST_NUMBER ){
					win.m_infos_size = (short)LIST_NUMBER;
				}
				for (int i = 0; i < win.m_infos_size; i++) {
					SimpleRole role = new SimpleRole();
					role.m_gameID = dis.readLong(); //id 
					role.m_name = dis.readUTF(); //名字
					role.m_family = dis.readUTF();//家族
					role.m_contrbution = dis.readLong();//贡献值
					role.m_camp = dis.readByte();//阵营
					win.roleList.addElement(role);
				}
				win.initRankingLists();				
			}
			GameManager.getInstance().m_game_message.unlockNetwork();
		}catch (Exception e) {
			GameManager.getInstance().m_game_message.unlockNetwork();
			Tools.debug(e);
		}	
		win.registerTouch();
	}
	
	/** 创建战功排行界面 */
	public static final void recvMilitaryExploitsRankingList(DataInputStream dis)
	{
		UIRankingLists win = (UIRankingLists)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_GRADERANK);
		if( win == null ){
			win = (UIRankingLists)UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_GRADERANK);
		}
		try{
			win.m_type = 6;
			synchronized (win) {
				win.roleList.removeAllElements();
				win.m_page_index = dis.readShort();//当前页数
				win.m_page_total = dis.readShort();//总页数
				win.m_infos_size = dis.readShort();//当前页内容数量
				if( win.m_infos_size > LIST_NUMBER ){
					win.m_infos_size = (short)LIST_NUMBER;
				}
				for (int i = 0; i < win.m_infos_size; i++) {
					SimpleRole role = new SimpleRole();
					role.m_gameID = dis.readLong(); //id 
					role.m_name = dis.readUTF(); //名字
					role.m_militaryexploits = dis.readLong();//战功
					role.m_camp = dis.readByte();//阵营
					win.roleList.addElement(role);
				}
				win.initRankingLists();
			}
			GameManager.getInstance().m_game_message.unlockNetwork();
		}catch (Exception e) {
			GameManager.getInstance().m_game_message.unlockNetwork();
			Tools.debug(e);
		}	
		win.registerTouch();
	}
	
	/** 创建采集排行界面 */
	public static final void recvCollectionRankingList(DataInputStream dis)
	{
		UIRankingLists win = (UIRankingLists)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_GRADERANK);
		if( win == null ){
			win = (UIRankingLists)UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_GRADERANK);
		}
		try{
			win.m_type = 7;
			synchronized (win) {
				win.roleList.removeAllElements();
				win.m_page_index = dis.readShort();//当前页数
				win.m_page_total = dis.readShort();//总页数
				win.m_infos_size = dis.readShort();//当前页内容数量
				if( win.m_infos_size > LIST_NUMBER ){
					win.m_infos_size = (short)LIST_NUMBER;
				}
				for (int i = 0; i < win.m_infos_size; i++) {
					SimpleRole role = new SimpleRole();
					role.m_gameID = dis.readLong(); //id 
					role.m_name = dis.readUTF(); //名字
					role.m_collection = dis.readInt();//采集
					role.m_camp = dis.readByte();//阵营
					win.roleList.addElement(role);
				}
				win.initRankingLists();
			}
			GameManager.getInstance().m_game_message.unlockNetwork();
		}catch (Exception e) {
			GameManager.getInstance().m_game_message.unlockNetwork();
			Tools.debug(e);
		}	
		win.registerTouch();
	}
	
	/** 创建攻伐排行界面 */
	public static final void recvAttackRankingList(DataInputStream dis)
	{
		UIRankingLists win = (UIRankingLists)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_GRADERANK);
		if( win == null ){
			win = (UIRankingLists)UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_GRADERANK);
		}
		try{
			win.m_type = 8;
			synchronized (win) {
				win.roleList.removeAllElements();
				win.m_page_index = dis.readShort();//当前页数
				win.m_page_total = dis.readShort();//总页数
				win.m_infos_size = dis.readShort();//当前页内容数量
				if( win.m_infos_size > LIST_NUMBER ){
					win.m_infos_size = (short)LIST_NUMBER;
				}
				for (int i = 0; i < win.m_infos_size; i++) {
					SimpleRole role = new SimpleRole();
					role.m_gameID = dis.readLong(); //id 
					role.m_name = dis.readUTF(); //名字
					role.m_attack = dis.readInt();//攻伐成功次数
					role.m_camp = dis.readByte();//阵营
					win.roleList.addElement(role);
				}
				win.initRankingLists();
			}
			GameManager.getInstance().m_game_message.unlockNetwork();
		}catch (Exception e) {
			GameManager.getInstance().m_game_message.unlockNetwork();
			Tools.debug(e);
		}	
		win.registerTouch();
	}
	
	/** 创建社交排行界面 */
	public static final void recvSocialContactRankingList(DataInputStream dis)
	{
		UIRankingLists win = (UIRankingLists)UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_ID_GRADERANK);
		if( win == null ){
			win = (UIRankingLists)UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_GRADERANK);
		}
		try{
			win.m_type = 9;
			synchronized (win) {
				win.roleList.removeAllElements();
				win.m_page_index = dis.readShort();//当前页数
				win.m_page_total = dis.readShort();//总页数
				win.m_infos_size = dis.readShort();//当前页内容数量
				if( win.m_infos_size > LIST_NUMBER ){
					win.m_infos_size = (short)LIST_NUMBER;
				}
				for (int i = 0; i < win.m_infos_size; i++) {
					SimpleRole role = new SimpleRole();
					role.m_gameID = dis.readLong(); //id 
					role.m_name = dis.readUTF(); //名字
					role.m_popularity = dis.readInt();//知名度
					role.m_camp = dis.readByte();//阵营
					win.roleList.addElement(role);
				}
				win.initRankingLists();
			}
			GameManager.getInstance().m_game_message.unlockNetwork();
		}catch (Exception e) {
			GameManager.getInstance().m_game_message.unlockNetwork();
			Tools.debug(e);
		}	
		win.registerTouch();
	}
}
